package com.jic.market.mapper;

import com.jic.market.entity.PromotionEntity;
import com.jic.market.impl.rest.discountamount.po.PromotionPo;
import com.jic.market.orm.BaseMapper;
import com.jic.market.orm.Pagination;
import com.jic.market.request.PromotionPolymericRequest;
import com.jic.market.request.QueryPromotionListRequest;
import com.jic.market.response.PromotionPolymericResponse;
import com.jic.market.response.PromotionResponse;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

@Repository
public interface PromotionEntityMapper extends BaseMapper<PromotionEntity>{

    /**
     *  通过idList 查询促销列表
     *  @return
     */
    List<PromotionEntity> queryPromotionListByIds(@Param("list") List<Long> idList);

    int countOfTemplate(PromotionEntity promotionEntity);

    List<PromotionEntity> findOfPage(@Param("po") PromotionEntity var1, @Param("page") Pagination var2);

    List<PromotionEntity> queryPage(@Param("startIndex") int startIndex, @org.apache.ibatis.annotations.Param("limit") int limit, @org.apache.ibatis.annotations.Param("promotion") PromotionEntity promotion);

    long queryPageCount(PromotionEntity promotion);

    List<PromotionEntity> findOfPageByDept(@Param("po") PromotionEntity var1, @Param("page") Pagination var2);

    int countByDept(@Param("po") PromotionEntity var1);

    List<PromotionPo> queryPromotionBySkuId(@Param("skuId") Long skuId);

    /** 查询单品类活动 */
    PromotionEntity querySinglePromotionBySkuId(@Param("skuId") Long skuId);

    /**
     * 根据 promotionCode查询 促销信息
     * @param promotionCode
     * @return
     */
    PromotionEntity queryByPromotionCode(String promotionCode);

    List<PromotionEntity> findByThirdSkuIdsAndFrontPromotionTypeList(@Param("thirdSkuIds")List<String> thirdSkuIds, @Param("frontPromotionTypeList")List<Integer> frontPromotionTypeList);
    List<String> findThirdSkuIdsBySkuIdsAndId(@Param("thirdSkuIds")List<String> thirdSkuIds, @Param("id")Long id);

    List<PromotionResponse> queryPromotionList(@Param("po") QueryPromotionListRequest queryPromotionListRequest);

    Long queryPromotionListCount(@Param("po") QueryPromotionListRequest queryPromotionListRequest);

    @Select("select * from promotion where end_time >= #{startTime} and end_time < #{endTime} and status = 11 and now() > end_time")
    List<PromotionEntity> queryEnd(@Param("startTime") Date startTime, @Param("endTime") Date endTime);


    PromotionPolymericResponse queryPromotionPolyInfo(@Param("request") PromotionPolymericRequest request);
}

